home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Rice_CMS / gopher24 / gopsrvau.exec < prev    next >
Encoding:
Text File  |  1993-01-18  |  3.0 KB  |  81 lines

  1. /*
  2.  *        Name: GOPSRVAU EXEC, authorization function
  3.  *              returns TRUE (1) if the file/menu may be retrieved
  4.  *              returns FALSE (0) otherwise
  5.  *        Date: 1993-Jan-18
  6.  *      Author: Rick Troth, Rice University, Information Systems
  7.  *
  8.  *              This file is part of CMS Gopher.
  9.  */
  10.  
  11. /*
  12.  *      Copyright 1993 Richard M. Troth.   This software was developed
  13.  *      with resources provided by Rice University and is intended
  14.  *      to serve Rice's user community.   Rice has benefitted greatly
  15.  *      from the free distribution of software,  therefore distribution
  16.  *      of unmodified copies of this material is not restricted.
  17.  *      You may change your own copy as needed.   Neither Rice
  18.  *      University nor any of its employees or students shall be held
  19.  *      liable for damages resulting from the use of this software.
  20.  */
  21.  
  22. /* ---------------------------------------------------------- AUTHORIZED
  23.  * Verify that the client is allowed access, based on IP addr or name.
  24.  * (we originally used an internal routine called IPA2C(),  but Arty's
  25.  * RXSOCKET provides an Inet_addr() function,  which is now preferred)
  26.  */
  27. AUTHORIZED:
  28. Parse Upper Arg Client,AuthList
  29. If AuthList = "" Then Return 1
  30. ClientAddr = Inet_addr(Client)
  31.  
  32. rc = Socket('GetHostByAddr', ClientAddr, 'ClientName')
  33. If rc = "-1" Then ClientName = Client
  34. Say "Client looks like" ClientName Inet_ntoa(ClientAddr)
  35. Upper ClientName
  36.  
  37. allow = 1
  38. Do While AuthList ^= ""
  39.  
  40.     Parse Var AuthList Auth AuthList
  41.     If Auth = "DENY" Then Do
  42.         allow = 0; Parse Var AuthList Auth AuthList
  43.         End  /*  If  ..  Do  */
  44.     If Auth = "ALLOW" Then Do
  45.         allow = 1; Parse Var AuthList Auth AuthList
  46.         End  /*  If  ..  Do  */
  47.     Say "Auth" Auth
  48.     If Auth = '*' Then Return allow
  49.  
  50.     Parse Var Auth Auth "," AuthMask "," .
  51.     AuthAddr = Inet_addr(Auth)
  52.     If AuthAddr = "-1" Then Do              /* process as a name spec */
  53.         If Left(Auth,1) = '.' Then Do
  54.             TruncName = Right(ClientName,Length(Auth))
  55.             Say "Truncated ClientName" TruncName
  56.             If TruncName = Auth Then Return allow
  57.             End  /*  If  ..  Do  */
  58.         Else If ClientName = Auth Then Return allow
  59.         End  /*  If  ..  Do  */
  60.  
  61.     Else Do                                 /* must be a numeric spec */
  62.         AuthMask = Inet_addr(AuthMask)
  63.         If AuthMask = "-1" Then Do
  64.             AuthMask = bitand(AuthAddr,'C0000000'x)
  65.             Select  /*  AuthMask  */
  66.                 When AuthMask = '00000000'x Then AuthMask = 'FF000000'x
  67.                 When AuthMask = '80000000'x Then AuthMask = 'FFFF0000'x
  68.                 When AuthMask = 'C0000000'x Then AuthMask = 'FFFFFF00'x
  69.                 End  /*  Select  AuthMask  */
  70.             End  /*  If  ..  Do  */
  71.         Say "ADDR" c2x(AuthAddr) "MASK" c2x(AuthMask)
  72.         AuthAddr = bitxor(AuthAddr,ClientAddr)
  73.         AuthAddr = bitand(AuthAddr,AuthMask)
  74.         If AuthAddr = '00000000'x Then Return allow
  75.         End  /*  Else  Do  */
  76.  
  77.     End  /*  Do  While  */
  78.  
  79. Return 0
  80.  
  81.